package xycdao

import (
	"Cgo/backend/models"
	"Cgo/global"
)

type xycShopDao struct{}

var XycShopDao = xycShopDao{}

// 根据id查询商品,不传id则查询所有商品
func (xycShopDao) FindShopByIdDao(shop models.XycShop) ([]models.XycShop, error) {
	var shops []models.XycShop
	if r := global.DB.Where(&shop).Find(&shops); r.Error != nil {
		return shops, r.Error
	} else {
		return shops, nil
	}
}

// 添加商品
func (xycShopDao) AddShopDao(shop models.XycShop) error {
	if r := global.DB.Create(&shop); r.Error != nil {
		return r.Error
	} else {
		return nil
	}
}

// 删除商品
func (xycShopDao) DeleteShopDao(shop models.XycShop) error {
	if r := global.DB.Delete(&shop); r.Error != nil {
		return r.Error
	} else {
		return nil
	}
}

// 更新商品
func (xycShopDao) UpdateShopDao(shop models.XycShop) error {
	if r := global.DB.Save(&shop); r.Error != nil {
		return r.Error
	} else {
		return nil
	}
}
